using System;
using System.Collections;

namespace Sedna.Core.Controller.Configurations
{
    [Obsolete("use GenericCommandArgumentGenerator")]
	public class ExecutionContextCommandArgumentGenerator : ICommandArgumentGenerator
	{

		private ICommandArgumentGenerator next = CommandConfiguration.EmptyStringCommandArgumentGenerator.Instance;
		private IDictionary contextNames; 

		public ICommandArgumentGenerator Next
		{
			set { next = value; }
		}

		public IDictionary ContextNames
		{
			set { contextNames = value; }
		}

		public string GenerateCommandArguments(ICommandConfiguration configuration, IExecutionContext executionContext)
		{
			return BuildArguments(executionContext) + next.GenerateCommandArguments(configuration, executionContext);
		}

		private string BuildArguments(IExecutionContext executionContext)
		{
			if(contextNames == null || contextNames.Count == 0)
			{
				return string.Empty;
			}

			string result = "";
			for(IDictionaryEnumerator en = contextNames.GetEnumerator(); en.MoveNext();)
			{
				result += String.Format("{0}={1};", en.Key, executionContext[en.Value]);
			}
			return result;
		}
	}
}
